import time
import main


# 使用该方法需要将fault_list.txt和success_list.txt文件清空
def repeat_send_email():
    g_email_list = []
    y_email_list = []
    email_list = ['sarpbar@hotmail.com',
                  'angel143282@hotmail.com',
                  'Larouex69@yahoo.com',
                  'elite137@hotmail.com',
                  'antwoinedavis45@mail.com',
                  't.kundu@mail.com',
                  'abdelmoula1988@mail.com',
                  'honeybaby261@mail.com',
                  'adnice72@mail.com',
                  'Loveayleen2012@mail.com',
                  'venkata.valluru@hotmail.com',
                  'iloveblacchyna15@mail.com',
                  'Callie.taken@outlook.com',
                  'grs6@aol.com',
                  'nguyenthu_thao@hotmail.com',
                  'parag.malankar@mail.com',
                  'Pandaysomi@mail.com',
                  'Saifsohel@mail.com',
                  'miteshgiddia@mail.com',
                  'lolojames442@mail.com',
                  'Ayatabdelsalam@hotmail.com',
                  'Media@mail.com',
                  'omayrayvelisse@mail.com',
                  'Gaurav.mittal18@mail.com',
                  'tiffanydavis@mail.com',
                  'vijethkk@mail.com',
                  'missybry11@mail.com',
                  'nazim159@mail.com',
                  'mariswatson2@mail.com',
                  'stephanie.mire@mail.com',
                  'Jess.trinklein@mail.com',
                  'negegoal@mail.com',
                  'Serve.a.chef@mail.com',
                  'Aanand17@mail.com',
                  'mabasb118@mail.com',
                  'Debby1162@msn.com',
                  'abgpkfw@mail.com',
                  'wadeelizabeth117@mail.com',
                  'Bhowmickbiltu@mail.com',
                  'traciethomas00@mail.com',
                  'tdebnath09@yahoo.com',
                  'Meowlissa11@yahoo.com',
                  'nandhak@yahoo.com',
                  'Justinec.garcia@yahoo.com',
                  'Christinakorom@yahoo.com',
                  'dualpcs@yahoo.com',
                  'elizabethashleyreyes@yahoo.com',
                  'photosbyjuanita@yahoo.com',
                  'alishzaiboo@yahoo.com',
                  'dolphin12122002@yahoo.com',
                  'ryanzimmerman6@yahoo.com',
                  'm_jawad1986@yahoo.com',
                  'Brat71@yahoo.com',
                  'Chavez.cristina87@yahoo.com',
                  'MarsFlower819@yahoo.com',
                  'J71920506@yahoo.com',
                  'vincent_kirchoff20@yahoo.com',
                  'Mouthy25149@yahoo.com',
                  'Tragiang2606@yahoo.com',
                  'asiff2k@yahoo.com']

    obj = open("email2.txt")
    try:
        gmail_file_context = obj.read()
    finally:
        obj.close()

    obj = open("email3.txt")
    try:
        ymail_file_context = obj.read()
    finally:
        obj.close()
    for email in email_list:
        if email.split("@")[1] == "yahoo.com":
            y_email_list.append(email)
        else:
            g_email_list.append(email)

    for i in range(0, len(g_email_list), 14):
        send_email_list = g_email_list[i:i + 14]
        time.sleep(2)
        main.send_email(send_email_list, gmail_file_context)

    for i in range(0, len(y_email_list), 14):
        send_email_list = y_email_list[i:i + 14]
        time.sleep(2)
        main.send_email(send_email_list, ymail_file_context)


def operate_fault():
    with open("fault_list.txt", 'w+', encoding='utf-8') as f:
        all_email_str = f.read()
        f.truncate(0)

    obj = open("email2.txt")
    try:
        gmail_file_context = obj.read()
    finally:
        obj.close()
    if all_email_str:
        all_email_str = all_email_str.split("|")
        for email_str in all_email_str:
            email_set = email_str.split(" ")
            if email_set[0] != "":
                print("重新发送数据,失败列表,email_set为%s", str(email_set))
                main.send_email(email_set, gmail_file_context)
        else:
            print("暂无出错数据")


if __name__ == '__main__':
    repeat_send_email()
